package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.MallProductEntity;
import com.company.project.service.MallProductService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2021-06-28 18:58:43
 */
@Controller
@RequestMapping("/")
public class MallProductController {
    @Autowired
    private MallProductService mallProductService;



    @ApiOperation(value = "新增")
    @PostMapping("mallProduct/add")
    @RequiresPermissions("mallProduct:add")
    @ResponseBody
    public DataResult add(@RequestBody MallProductEntity mallProduct){
        mallProductService.save(mallProduct);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("mallProduct/delete")
    @RequiresPermissions("mallProduct:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        mallProductService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("mallProduct/update")
    @RequiresPermissions("mallProduct:update")
    @ResponseBody
    public DataResult update(@RequestBody MallProductEntity mallProduct){
        mallProductService.updateById(mallProduct);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("mallProduct/listByPage")
    @RequiresPermissions("mallProduct:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody MallProductEntity mallProduct){
        Page page = new Page(mallProduct.getPage(), mallProduct.getLimit());
        LambdaQueryWrapper<MallProductEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(MallProductEntity::getId, mallProduct.getId());
        IPage<MallProductEntity> iPage = mallProductService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
